package com.yedean.factory.support;

import com.yedean.factory.BeansException;
import com.yedean.factory.config.BeanDefinition;

/**
 * AbstractAutowiredCapableBeanFactory 自动装配能力的bean工厂
 *
 * @author yedean
 * @date 2022/6/28
 */
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory{

    /**
     * 创建bean实例
     * @param name beanName
     * @param definition bean定义信息
     * @return bean
     */
    @Override
    protected Object createBean(String name, BeanDefinition definition) throws BeansException {
        Object bean;
        try {
            //只考虑无参构造的反射创建
            bean = definition.getBeanClass().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new BeansException("反射创建对象时发生错误",e);
        }
        //添加到单例集合中
        addSingleton(name,bean);
        
        return bean;
    }
}
